home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / PERSPECT.C < prev    next >
C/C++ Source or Header  |  1980-01-03  |  4KB  |  156 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * Perspective definition.
  25.  */
  26.  
  27. #include <InterViews/perspective.h>
  28. #include <InterViews/interactor.h>
  29.  
  30. class ViewList {
  31. public:
  32.     Interactor* view;
  33.     ViewList* next;
  34.  
  35.     ViewList (Interactor* i) { view = i; next = nil; }
  36. };
  37.  
  38. Perspective::Perspective () {
  39.     views = nil;
  40.     x0 = 0; y0 = 0;
  41.     width = 0; height = 0;
  42.     curx = 0; cury = 0;
  43.     curwidth = 0; curheight = 0;
  44.     sx = 0; sy = 0;
  45.     lx = 0; ly = 0;
  46.     Reference();
  47. }
  48.  
  49. Perspective::Perspective (Perspective& p) {
  50.     views = nil;
  51.     x0 = p.x0;
  52.     y0 = p.y0;
  53.     width = p.width;
  54.     height = p.height;
  55.     curx = p.curx;
  56.     cury = p.cury;
  57.     curwidth = p.curwidth;
  58.     curheight = p.curheight;
  59.     sx = p.sx;
  60.     sy = p.sy;
  61.     lx = p.lx;
  62.     ly = p.ly;
  63.     Reference();
  64. }
  65.  
  66. Perspective::~Perspective () {
  67.     register ViewList* e;
  68.     register ViewList* next;
  69.  
  70.     for (e = views; e != nil; e = next) {
  71.     next = e->next;
  72.     delete e;
  73.     }
  74. }
  75.  
  76. void Perspective::Init (Coord ix0, Coord iy0, Coord iwidth, Coord iheight) {
  77.     x0 = ix0; y0 = iy0;
  78.     width = iwidth; height = iheight;
  79.     curx = x0; cury = y0;
  80. }
  81.  
  82. void Perspective::Attach (Interactor* i) {
  83.     register ViewList* e;
  84.  
  85.     e = new ViewList(i);
  86.     e->next = views;
  87.     views = e;
  88.     Reference();
  89. }
  90.  
  91. void Perspective::Detach (Interactor* i) {
  92.     register ViewList* e;
  93.     register ViewList* prev;
  94.  
  95.     prev = nil;
  96.     for (e = views; e != nil; e = e->next) {
  97.     if (e->view == i) {
  98.         if (prev == nil) {
  99.         views = e->next;
  100.         } else {
  101.         prev->next = e->next;
  102.         }
  103.         e->view = nil;
  104.         e->next = nil;
  105.         delete e;
  106.         Unreference();
  107.         break;
  108.     }
  109.     prev = e;
  110.     }
  111. }
  112.  
  113. void Perspective::Update () {
  114.     register ViewList* e;
  115.  
  116.     for (e = views; e != nil; e = e->next) {
  117.     e->view->Update();
  118.     }
  119. }
  120.  
  121. boolean Perspective::operator == (Perspective& p) {
  122.     return
  123.     x0 == p.x0 && y0 == p.y0 &&
  124.     width == p.width && height == p.height &&
  125.     curx == p.curx && cury == p.cury &&
  126.     curwidth == p.curwidth && curheight == p.curheight &&
  127.     sx == p.sx && sy == p.sy &&
  128.     lx == p.lx && ly == p.ly;
  129. }
  130.  
  131. boolean Perspective::operator != (Perspective& p) {
  132.     return
  133.     x0 != p.x0 || y0 != p.y0 ||
  134.     width != p.width || height != p.height ||
  135.     curx != p.curx || cury != p.cury ||
  136.     curwidth != p.curwidth || curheight != p.curheight ||
  137.     sx != p.sx || sy != p.sy ||
  138.     lx != p.lx || ly != p.ly;
  139. }
  140.  
  141. Perspective& Perspective::operator = (Perspective& p) {
  142.     x0 = p.x0;
  143.     y0 = p.y0;
  144.     width = p.width;
  145.     height = p.height;
  146.     curx = p.curx;
  147.     cury = p.cury;
  148.     curwidth = p.curwidth;
  149.     curheight = p.curheight;
  150.     sx = p.sx;
  151.     sy = p.sy;
  152.     lx = p.lx;
  153.     ly = p.ly;
  154.     return *this;
  155. }
  156.